package io.finer.erp.jeecg.bas.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import io.finer.erp.jeecg.bas.entity.BasWarehouse;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * @Description: 仓库
 * @Author: jeecg-boot
 * @Date:   2020-04-01
 * @Version: V1.0
 */
public interface BasWarehouseMapper extends BaseMapper<BasWarehouse> {

	/**
	 * 编辑节点状态
	 * @param id
	 * @param status
	 */
	void updateTreeNodeStatus(@Param("id") String id,@Param("status") String status);
	
	/**
	 * @Description 获取仓库的根节点
	 * @param id
	 * @return
	 * Create at: 2020-10-21 08:55:28
	 * @author: duany
	 * Revision:
	 *    2020-10-21 08:55:28 - first revision by duany
	 *        
	 */
	@Select("select * from (SELECT @r as _id, (select @r := pid FROM bas_warehouse where id = _id) as 2v2, @l := @l + 1 as lvl FROM (SELECT @r := #{id}, @l:=0) vars, bas_warehouse c WHERE @r is not null) T1 LEFT JOIN bas_warehouse T2 ON T1._id=T2.id WHERE t2.pid=0")
	BasWarehouse getRootWarehouse(@Param("id") String id);

}
